﻿using System.Collections.Generic;

namespace Missbot.Common
{
    /// <summary>
    /// 数据托管接口
    /// </summary>
    public interface IDataMgr
    {
        /// <summary>
        /// 刷新数据
        /// </summary>
        void RefreshData();
    }

    /// <summary>
    /// 数据刷新管理器
    /// </summary>
    public class DataRefreshSvc : ISingleton
    {
        /// <summary>
        /// 所有实行数据托管的实例
        /// </summary>
        private readonly List<IDataMgr> AllMgrs = new();

        /// <summary>
        /// 注册数据托管
        /// </summary>
        /// <param name="mgr"></param>
        public void Register(IDataMgr mgr)
        {
            AllMgrs.Add(mgr);
        }

        /// <summary>
        /// 刷新所有托管数据
        /// </summary>
        /// <returns></returns>
        public int RefreshAll()
        {
            foreach (var mgr in AllMgrs)
            {
                mgr.RefreshData();
            }

            return AllMgrs.Count;
        }
    }
}